﻿using System;
using MaLu.Common;
using MaLu.Data;
using System.Data;

namespace MaluJg.web.Groups
{
    public partial class GBusiDetail : GBusiPage
    {
        protected Guid RecordID
        {
            get
            {
                Guid gd = Guid.NewGuid();
                if (Request["ID"] != null)
                    gd = new Guid(Request["ID"]);
                else
                {
                    if (ViewState["ID"] != null)
                        gd = (Guid)ViewState["ID"];


                }
                if (ViewState["ID"] == null)
                    ViewState["ID"] = gd;
                return gd;
            }
            set
            {
                ViewState["ID"] = value;
            }

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "组务详细清单";
            this.UseTabber = true;
            if (!IsPostBack)
            {
               BindData();
            }
        }
        private void BindData()
        {
            DataTable dt = SqlHelper.Instance.ExecuteDataTable(Provider, "select * from [GroupBusiness]  where id ='" + RecordID + "'");
            if (dt.Rows.Count > 0)
            {
                
               
                DataRow dr = dt.Rows[0];

               lbVillage.Text = dr["GroupName"].ToString().Replace("''", "'");
            
               lbComponent.Text = dr["Component"].ToString().Replace("''", "'");
              
               lbReward.Text = dr["Reward"].ToString().Replace("''", "'");
               lbHousing.Text = dr["Housing"].ToString().Replace("''", "'");
               lbPropertyRent.Text = dr["PropertyRent"].ToString().Replace("''", "'");
            
               lbOthers.Text = dr["Others"].ToString().Replace("''", "'");
            }

            dt = SqlHelper.Instance.ExecuteDataTable(Provider, "select ID, [Year] ,[Name]  ,[Amount]  from  [GroupFinance] where  [GroupRecordID]='" + RecordID + "' order by createtime desc ");
            rptItemList.DataSource = dt;
            rptItemList.DataBind();

          

        }
        protected void lbtnDelete_Click(object sender, EventArgs e)
        {
            string sql = string.Format("delete from [GroupBusiness] where id in ('{0}');delete from [GroupFinance] where GroupRecordID in ('{0}');", RecordID);

            SqlHelper.Instance.ExecuteNonQuery(Provider, sql);
            ClientScript.RegisterStartupScript(this.GetType(), "Delete", "<script>parent.location.href = parent.location.href</script>");
        }

    }
}
